package main

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

var donate_db , _ = sql.Open("mysql", "mt11235:hwqmingdi@tcp(127.0.0.1:3306)/charity?charset=utf8")

func AddDonateCount(id string, money string) error {
	_, err := donate_db.Exec(
		"update donate_count set sum=sum+? where id=?", money, id)
	if err != nil {
		log.Println(err)
		return err
	}
	return nil
}

func AskDonateCount(id string) (error, int, int) {
	row := donate_db.QueryRow("select sum, goal from donate_count where id=?", id)
	sum := 0
	goal := 0
	err := row.Scan(&sum, &goal)
	if err != nil {
		log.Println(err)
		return err, 0, 0
	}
	return nil, sum, goal
}